﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoSingleton<PlayerController>
{
    //DEMO VERSION ONLY
    public KeyCode KeyCode_GodMode = KeyCode.O;
    public KeyCode KeyCode_JumpLevel = KeyCode.P;
    public bool bIsGodMode = false;
    //DEMO VERSION ONLY

    public string Axis_P1_Horizontal = "Horizontal1";
    public string Axis_P1_Vertical = "Vertical1";
    public KeyCode KeyCode_P1_Shoot = KeyCode.Space;

    public bool bCanControlPlayer2 = false;
    public string Axis_P2_Horizontal = "Horizontal2";
    public string Axis_P2_Vertical = "Vertical2";

    //玩家绑定
    public KeyCode KeyCode_Players_Bind = KeyCode.Return;
    public bool bIsPlayersBind = false;

    public Vector2 P1_Input_Vector;
    public Vector2 P2_Input_Vector;

    void Update()
    {
        P1_Input_Vector = Vector2.zero;
        P2_Input_Vector = Vector2.zero;

        P1_Input_Vector = new Vector2(Input.GetAxis(Axis_P1_Horizontal), Input.GetAxis(Axis_P1_Vertical));
        EventMgr.Call(Events.ON_PLAYER1_INPUT, P1_Input_Vector);

        if (bCanControlPlayer2)
        {
            P2_Input_Vector = new Vector2(Input.GetAxis(Axis_P2_Horizontal), Input.GetAxis(Axis_P2_Vertical));
            if (!bIsPlayersBind)
            {
                EventMgr.Call(Events.ON_PLAYER2_INPUT, P2_Input_Vector);
            }
            else
            {
                EventMgr.Call(Events.ON_PLAYER2_INPUT, P1_Input_Vector);
            }
        }

        //Player1 Attack
        if (Input.GetKeyDown(KeyCode_P1_Shoot))
        {
            EventMgr.Call(Events.ON_PLAYER1_ATTACK);
        }

        //Players Bind
        if (Input.GetKeyDown(KeyCode_Players_Bind))
        {
            bIsPlayersBind = !bIsPlayersBind;
            EventMgr.Call(Events.ON_PLAYERS_BIND, bIsPlayersBind);
        }

        //DEMO VERSION ONLY
        if (Input.GetKeyDown(KeyCode_GodMode))
        {
            bIsGodMode = !bIsGodMode;
        }

        if (Input.GetKeyDown(KeyCode_JumpLevel))
        {
            LevelManager.Instance.LevelComplete();
        }
        //DEMO VERSION ONLY
    }
}
